/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package models.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import models.DBHandler;
import models.beans.AdminBean;

/**
 *
 * @author Group 3 Aprotrain Aptech Group3 Aprotrain Aptech
 */
public class AdminDAO {
    public static AdminBean login(String adminName, String password) throws Exception{
        AdminBean admin = null;
        Connection conn = DBHandler.getConnection();
        ResultSet rs = null;
        PreparedStatement pstm = null;
        try {            
            pstm = conn.prepareStatement("SELECT * FROM tblAdmin WHERE adminName = ? AND password = ?");
            pstm.setString(1, adminName);
            pstm.setString(2, password);
            rs = pstm.executeQuery();
            if(rs.next()){
               admin = new AdminBean();
               admin.setAdminName(rs.getString("adminName"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        DBHandler.closeDBObj(rs);
        DBHandler.closeDBObj(pstm);
        DBHandler.closeDBObj(conn);
        return admin;
    }
}
